//
//  UserViewController.m
//  Wujin
//
//  Created by cz on 2016/12/11.
//  Copyright © 2016年 dong. All rights reserved.
//

#import "UserViewController.h"
#import "OrderViewController.h"
#import "UserInfoViewController.h"

@interface UserViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;

@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;


@end

@implementation UserViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)setupUI {
    
    self.iconView.layer.cornerRadius = 40;
    self.iconView.layer.masksToBounds = YES;
    self.phoneLabel.text = F(@"%@-%@",[WJUser user].phone,[WJUser user].name) ;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self setupUI];

}

- (IBAction)seguePersonalInfo {
    
    [self performSegueWithIdentifier:@"PersonalInfo" sender:nil];
    
}

- (IBAction)logoffClicked{
    DLog(@"退出登录");
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults removeObjectForKey:@"Password"];
    
    [MRHud showWithSuccess:@"退出成功，请重新登录" afterDelay:1.0];
    NSString *sql = F(@"delete from db_goods");
    [dbase begin];
    BOOL success = [dbase exec:sql];
    [dbase commit];
    DLog(@"%d", success);
 
    [self presentViewController:[UIViewController storyboardWithName:@"Main" storyboardID:@"user"] animated:NO completion:nil];
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        OrderViewController *orderVc = [[OrderViewController alloc] init];
        orderVc.isFinished = YES;
        [self.navigationController pushViewController:orderVc animated:YES];
    }else if (indexPath.row == 1){
        OrderViewController *orderVc = [[OrderViewController alloc] init];
        orderVc.isFinished = NO;
        [self.navigationController pushViewController:orderVc animated:YES];
    }else if (indexPath.row == 2){
        [self performSegueWithIdentifier:@"modifyPassword" sender:nil];
    }else if (indexPath.row == 3){
        [self performSegueWithIdentifier:@"ContactUs" sender:nil];
    }
}

@end
